<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改学生信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=basePath%>/layui/css/layui.css" media="all">
  <script src="<%=basePath%>/js/jquery-3.2.1.min.js"></script>
</head>
<body>
<form class="layui-form" id ="form">
	<div class="layui-form-item" style="margin-top:50px;">
		<input class="layui-input" id="tId" style="display:none">
	    <div class="layui-form-item">
		    <label class="layui-form-label">学号：</label>
		    <div class="layui-input-inline">
			    <input class="layui-input" style="width:300px;" type = "text" id="tno" lay-verify="required" lay-reqtext="账号是必填项！" disabled="disabled" >
			</div>
		</div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">姓名：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tname" lay-verify="required" lay-reqtext="用户名是必填项！">
			</div>
		</div>
		<div class="layui-form-item">
		<!-- layui 与 jsp 冲突  单选框或起不了  -->
		    <label class="layui-form-label">性别：</label>
		    <div class="layui-input-inline">
		    <!-- <input  class="layui-input" style="width:300px;" type = "text" id="sex"> --> 
			  <input type="radio" name="sex" lay-filter="erweima" value="男" title="男" checked="checked">
			   <input type="radio" name="sex" lay-filter="erweima" value="女" title="女"  > 
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">密码：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tPassword">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">系部：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tDepartment">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">学科：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tObject">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">学厉：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tDegree">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">职称：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tJobs">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">研究方向：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="cDirection">
			</div>
		</div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">邮件：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="email">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">办公室：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tAddress">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">手机号：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="tPhone">
			</div>
		</div>
	    <div class="layui-form-item" style="margin-left:180px;margin-top:50px;">
			<button type="button" class="layui-btn" onclick="edit();">保存</button>
			<button type="button" class="layui-btn" onclick="back();">返回</button>
		</div>
 	 </div>
</form>
</body>


<script src="<%=basePath%>/js/vue.min.js"></script>
<script src="<%=basePath%>/layui/layui.js" charset="utf-8"></script>
<script>
layui.use('form',function(){
	var form = layui.form;
	$('#tId').val(localStorage.getItem("tId"));
	$('#tno').val(localStorage.getItem("tno"));
	$('#tname').val(localStorage.getItem("tname"));
	//$('#sex').val(localStorage.getItem("sex"));
	//单选框传值问题未解决
	$("input[type='radio']:checked").val(localStorage.getItem("sex"));
	$('#tPassword').val(localStorage.getItem("tPassword"));
	$('#tDepartment').val(localStorage.getItem("tDepartment"));
	$('#tObject').val(localStorage.getItem("tObject"));
	$('#tDegree').val(localStorage.getItem("tDegree"));
	$('#tJobs').val(localStorage.getItem("tJobs"));
	$('#cDirection').val(localStorage.getItem("cDirection"));
	$('#email').val(localStorage.getItem("email"));
	$('#tAddress').val(localStorage.getItem("tAddress"));
	$('#tPhone').val(localStorage.getItem("tPhone"));
	//全部更新 解决单选框不渲染
	form.render();
});

function edit(){
	var param = new Object();
	param.tId = $('#tId').val();
	param.tno  = $('#tno').val();
	param.tname = $('#tname').val();
	param.sex = $("input[type='radio']:checked").val();
	
	param.tPassword = $('#tPassword').val();
	param.tDepartment = $('#tDepartment').val();
	param.tObject = $('#tObject').val();
	param.tDegree = $('#tDegree').val();
	param.tJobs = $('#tJobs').val();
	param.cDirection = $('#cDirection').val();
	param.email = $('#email').val();
	param.tAddress = $('#tAddress').val();
	param.tPhone = $('#tPhone').val();
	console.log("send message:"+JSON.stringify(param));
	$.ajax({
		type:"GET",
		url:"/bysjxksys/admin/edit_teacher",
		dataType:"json",
		//contentType:"application/json",
        data:param,
		success: function(data){
			if(data.code==1){
				alert(data.msg);
			}else{
				alert("数据更新成功！");
				//window.location.reload();	
				parent.location.reload();
			}
		},
		error: function(data, type, err){
			console.log(type);
			console.log(err);
		}
	});
};

function back(){
	//当你在iframe页面关闭自身时
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
    window.location.reload();
}


</script>
</html>